﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_AgencyChildAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        { }

    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        Int64 AccountId_father, AccountId = 0;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            ///判断密码是否为空,两次输入的是否一致
            string str_mima1 = txtPwd_Bid.Text.ToString();
            string str_mima2 = txt_word_qr.Text.ToString();
            if (str_mima1 == "" || str_mima2 == "" || str_mima1 != str_mima2)
            {
                Response.Write("<script>alert('密码不能为空或两次输入的密码不一致,请重新输入！');</script>");
                return;
            }//////
            AccountId_father = SysFun.ToLong(_Account.AccountId);

            Db db = new Db();
            Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
            HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();


            Account.AccountName = txtAccountName.Text;
            ///判断是否添加过该用户
            string str_SQL = " select count(*) from account where accountname ='" + Account.AccountName + "'";
            DataTable gg = db.DataTable(str_SQL);
            string str_rows = gg.Rows[0][0].ToString();
            gg.Dispose();
            if (str_rows != "0")
            {
                Response.Write("<script>alert('此用户已添加！');</script>");
                return;
            }
            ////
            Account.Pwd_Bid = SysFun.PasswordEncrypt(txtPwd_Bid.Text);
            Account.Type = SysFun.ToTrim(rdoType.SelectedValue);
            oo.Insert(Account);
            oo.Dispose();
            System.Data.IDataReader dr;
            dr = db.DataReader("select AccountId from account  where AccountName='" + SysFun.ToTrim(txtAccountName.Text) + "'");
            while (dr.Read())
            {
                AccountId = SysFun.ToInt(dr["AccountId"]);
            }
            dr.Close();
            dr.Dispose();
            oo.Dispose();
            string strSql = "";

            strSql = "insert into AgencyChild (accountid,usercode,username,telephone,zc,accountId_father)";
            strSql += " values( ";
            strSql += "'" + AccountId + "',";
            strSql += "'" + SysFun.ToTrim(txtAccountName.Text) + "',";
            strSql += "'" + SysFun.ToTrim(txtUserName.Text) + "',";
            strSql += "'" + SysFun.ToTrim(txtTelephone.Text) + "',";
            strSql += "'" + SysFun.ToTrim(txtZC.Text) + "',";
            strSql += "'" + AccountId_father + "')";
            db.Command(strSql);

            db.Close();
            // HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "AgencyChild", strSql, "../Agency/AgencyChildAdd.aspx");

        }
        else
        {
            Response.Write("<script language=JavaScript>alert('您还没有登录，暂时无权添加子用户！！！');</script>");
        }
        Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }

}
